namespace IMPlant.Core.Data.Unity
{
    using IMPlant.Core.Data.Ado.BaseSupport;
    using System;
    using System.Data;
    using System.Data.Common;

    public class DBparameterBuild
    {
        public static DbParameter Build(string paraName, decimal value)
        {
            return CreatePara(DbType.Decimal, paraName, value);
        }

        public static DbParameter Build(string paraName, bool? value)
        {
            return CreatePara(DbType.Boolean, paraName, value);
        }

        public static DbParameter Build(string paraName, byte[] value)
        {
            return CreatePara(DbType.Binary, paraName, value);
        }

        public static DbParameter Build(string paraName, int value)
        {
            return CreatePara(DbType.Int64, paraName, value);
        }

        public static DbParameter Build(string paraName, double value)
        {
            return CreatePara(DbType.Double, paraName, value);
        }

        public static DbParameter Build(string paraName, Guid value)
        {
            return CreatePara(DbType.Guid, paraName, value);
        }

        public static DbParameter Build(string paraName, DateTime value)
        {
            return CreatePara(DbType.DateTime, paraName, value);
        }

        public static DbParameter Build(string paraName, DateTime? value)
        {
            return CreatePara(DbType.DateTime, paraName, value);
        }

        public static DbParameter Build(string paraName, bool value)
        {
            return CreatePara(DbType.Boolean, paraName, value);
        }

        public static DbParameter Build(string paraName, decimal? value)
        {
            return CreatePara(DbType.Decimal, paraName, value);
        }

        public static DbParameter Build(string paraName, double? value)
        {
            return CreatePara(DbType.Double, paraName, value);
        }

        public static DbParameter Build(string paraName, Guid? value)
        {
            return CreatePara(DbType.Guid, paraName, value);
        }

        public static DbParameter Build(string paraName, int? value)
        {
            return CreatePara(DbType.Int16, paraName, value);
        }

        public static DbParameter Build(string paraName, string value)
        {
            return CreatePara(DbType.String, paraName, value);
        }

        private static DbParameter CreatePara(DbType type, string paraName, object value)
        {
            DbParameter parameter = SqlClientDataBase.ProviderFactory.CreateParameter();
            parameter.DbType = type;
            parameter.ParameterName = paraName;
            if (value != null)
            {
                parameter.Value = value;
                return parameter;
            }
            parameter.Value = DBNull.Value;
            return parameter;
        }
    }
}

